#!/bin/sh
#===========HEADER==================================================|
#AUTHOR
#  Jefferson Rocha <lrcjefferson@gmail.com>
#
#PROGRAM
#  infonow - All system information!
#
#SMALL DESC
#  Look all information on your OS
#
#CHANGELOG
#  0.3 - Jefferson Rocha
#  - Change all grep, cut, head etc... for awk.
#===================================================================|

#=====VARS==========================|
name="infonow"
version="0.3"
#===================================|


#=====TEST==========================|
[ "$UID" -ne "0" ] && {
    printf '%b\n' "Only Root!"
    exit 1
}
#===================================|


#====FUNC===========================|
_usage(){
cat << EOF
NAME
   infonow...[OPTION]

USAGE
   help, usage      Open this help option and exit.

VERSION
   ${version}

AUTHOR
   Jefferson Rocha <lrcjefferson@gmail.com>

EOF

exit 0
}

information(){
  #===> Running System
  OS_SYSTEM=$(awk 'BEGIN{FS="="} /^NAME/{print $2}' /etc/os-release)     # Find name
  OS_SYSTEM="${OS_SYSTEM//\"/}"                                          # Have " ? no more.
  #===> CPU
  CPU=$(awk 'BEGIN{FS=":"}/^model.*name/{print $2}' /proc/cpuinfo)       # Find model name
  CPU="${CPU/ /}"                                                        # space? noooo
  #===> SPACE
  HD_TOTAL=$(df -HP | awk '/.*\/root/{print $2}')               # Total space
  HD_DISP=$(df -HP | awk '/.*\/root/{print $4}')                # Available space
  #===> UPTIME
  UPTIME=$(uptime -p)
  UPTIME="${UPTIME/up/}"                                        # cut initial up
  UPTIME="${UPTIME/ /}"                                         # BYE BYE SPACE
  #===> MEM
  RAM=$(free -ht | awk '/^[Mm]em.*/{print $2}')                 # RAM?
  #===> KERNEL
  KERNEL_VERSION=$(uname -r)                                    # Need a kernel baby
  #===> GATEWAY
  GATEWAY=$(ip route | awk '/^default/{print $3}')              # Gateway
}
#===================================|

if [ "$1" = "usage" ] || [ "$1" = "help" ];then
     _usage
fi


clear
# Print STDOUT
information # Call Function
cat <<END
$name Version $version

+-+-+-+-+-+-+-+-+-+-+-+-+-System Information+-+-+-+-+-+-+-+-+-+-+-+-+-
Operational System: $OS_SYSTEM
Lang:               $LANG
Kernel Version:     $KERNEL_VERSION
Cpu:                $CPU
Uptime:             $UPTIME
Total Ram:          $RAM
HD TOTAL:           $HD_TOTAL
HD DISP :           $HD_DISP
Gateway:            $GATEWAY
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
END
